// pages/search_conten/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_fuc: true,
    search_value: "",
    hotSearch: [],
    search_history:[]
  },
  get_val: function (e) {
      this.setData({
        search_value: e.detail.value
      })
  },
  search: function () {
    var that = this 
    wx.redirectTo({
      url: '/pages/search_page/search_page?value=' + this.data.search_value,
    })
    app.set_stor(this.data.search_value)
  },
  confirm_search: function (e) {
    wx.redirectTo({
      url: '/pages/search_page/search_page?value=' + e.detail.value,
    })
    app.set_stor(e.detail.value)
  },

  check: function (e) {
    var value = e.currentTarget.dataset.value
    app.set_stor(value)
    wx.redirectTo({
      url: '/pages/search_page/search_page?value=' + value,
    })
    this.setData({
      search_value: value
    })
  },
  clear_history:function(){
    var that = this
    wx.removeStorage({
      key: 'search_history',
      success: function() {
        that.setData({
          search_history:[]
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getStorage({
      key: 'search_history',
      complete: function(res) {
       if(res.data){
         that.setData({
           search_history: res.data.list
         })
       }
      },
    })
    app.ajax({
      url: app.host + "mall/goods/hotSearch",
      success:function(res){
        that.setData({
          hotSearch: res.data.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})